
#ifndef _NETFW_FUNCION_H
#define _NETFW_FUNCION_H

#include "RtError.h"
#include "RtThreadInterface.h"

namespace Function
{
	
	class Functor : public IRtEvent
	{
	public:
		Functor()
		{
		}
		virtual ~Functor()
		{

		}
	public:
		virtual RtResult OnEventFire()
		{
			return RT_OK;
		}
	};

	/*<@ Static/global functor */
	template<typename FunPtr>
	class Functor0 : public Functor
	{
	public:
		Functor0(const FunPtr& funPtr) : _funPtr(funPtr)
		{
		}
		virtual ~Functor0()
		{
		}
	public:
		virtual RtResult OnEventFire()
		{
			_funPtr();
			return RT_OK;
		}
	
	private:
		FunPtr _funPtr;
	};

	template<typename FunPtr, typename Para1>
	class Functor1 : public Functor
	{
	public:
		Functor1(const FunPtr& funPtr, Para1 p1) : _funPtr(funPtr), _p1(p1)
		{
		}

		virtual ~Functor1()
		{
		}
	public:
		virtual RtResult OnEventFire()
		{
			_funPtr(_p1);
			return RT_OK;
		}
	private:
		FunPtr _funPtr;
		Para1  _p1;
	};

	template<typename FunPtr, typename Para1, typename Para2>
	class Functor2 : public Functor
	{
	public:
		Functor2(const FunPtr& funPtr, Para1 p1, Para2 p2) :
							_funPtr(funPtr), _p1(p1), _p2(p2)
		{
		}

		virtual ~Functor2()
		{
		}
		
	public:
		virtual RtResult OnEventFire()
		{
			_funPtr(_p1, _p2);
			return RT_OK;
		}

		FunPtr _funPtr;
		Para1  _p1;
		Para2  _p2;
	};

	template<typename FunPtr, typename Para1, typename Para2, typename Para3>
	class Functor3 : public Functor
	{
	public:
		Functor3(const FunPtr& funPtr, Para1 p1, Para2 p2, Para3 p3) :
				 _funPtr(funPtr), _p1(p1), _p2(p2), _p3(p3)
		{		
		}
		virtual ~Functor3()
		{
		}
	public:
		virtual RtResult OnEventFire()
		{
			_funPtr(_p1, _p2, _p3);
			return RT_OK;
		}
	private:
		FunPtr _funPtr;
		Para1  _p1;
		Para2  _p2;
		Para3  _p3;
	};

	template<typename FunPtr, typename Para1, typename Para2, typename Para3,
			 typename Para4>
	class Functor4 : public Functor
	{
	public:
		Functor4(const FunPtr& funPtr, Para1 p1, Para2 p2, Para3 p3, Para4 p4) :
				 _funPtr(funPtr), _p1(p1), _p2(p2), _p3(p3), _p4(p4)
		{
		}
		virtual ~Functor4()
		{
		}
	public:
		virtual RtResult OnEventFire()
		{
			_funPtr(_p1, _p2, _p3, _p4);
			return RT_OK;
		}
	private:
		FunPtr _funPtr;
		Para1  _p1;
		Para2  _p2;
		Para3  _p3;
		Para4  _p4;
	};

    template<typename FunPtr, typename Para1, typename Para2, typename Para3,
             typename Para4, typename Para5>
    class Functor5 : public Functor
	{
	public:
		Functor5(const FunPtr& funPtr, Para1 p1, Para2 p2, Para3 p3, Para4 p4, Para5 p5) :
				 _funPtr(funPtr), _p1(p1), _p2(p2), _p3(p3), _p4(p4), _p5(p5)
		{
		}
		  virtual ~Functor5()
		  {
		  }
	public:
		virtual RtResult OnEventFire()
		{
			_funPtr(_p1, _p2, _p3);
			return RT_OK;
		}
	private:
		FunPtr _funPtr;
		Para1  _p1;
		Para2  _p2;
		Para3  _p3;
		Para4  _p4;
		Para5  _p5;
	};

	template<typename FunPtr, typename Para1, typename Para2, typename Para3,
             typename Para4, typename Para5, typename Para6>
    class Functor6 : public Functor
	{
	public:
		Functor6(const FunPtr& funPtr, Para1 p1, Para2 p2, Para3 p3, Para4 p4, 
                 Para5 p5, Para6 p6) : _funPtr(funPtr), _p1(p1), _p2(p2),
				 _p3(p3), _p4(p4), _p5(p5), _p6(p6)
		{
		}
        virtual ~Functor6()
		{
		}
	public:
		virtual RtResult OnEventFire()
		{
			_funPtr(_p1, _p2, _p3);
			return RT_OK;
		}
	private:
		FunPtr _funPtr;
		Para1  _p1;
		Para2  _p2;
		Para3  _p3;
		Para4  _p4;
		Para5  _p5;
		Para6  _p6;
	};

	/*<@ Member function */
	template<typename ObjPtr, typename FunPtr>
    class MemFunctor0 : public Functor 
	{
	public:
		MemFunctor0(const ObjPtr& objPtr, FunPtr funPtr) :
                    _objPtr(objPtr), _funPtr(funPtr)
		{
		}
		virtual ~MemFunctor0()
		{
		}	
	public:
		virtual RtResult OnEventFire()
		{
			(_objPtr->*_funPtr)();
			return RT_OK;
		}
	private:
		ObjPtr _objPtr;
		FunPtr _funPtr;
	};

	template<typename ObjPtr, typename FunPtr, typename Para1>
    class MemFunctor1 : public Functor 
	{
	public:
		MemFunctor1(const ObjPtr& objPtr, const FunPtr& funPtr, Para1 p1) :
                    _objPtr(objPtr), _funPtr(funPtr), _p1(p1)
		{
		}
		virtual ~MemFunctor1()
		{
		}	
	public:
		virtual RtResult OnEventFire()
		{
			(_objPtr->*_funPtr)(_p1);
			return RT_OK;
		}
	private:
		ObjPtr _objPtr;
		FunPtr _funPtr;
		Para1  _p1;
	};

	template<typename ObjPtr, typename FunPtr, typename Para1, 
             typename Para2>
    class MemFunctor2 : public Functor 
	{
	public:
		MemFunctor2(const ObjPtr& objPtr, const FunPtr& funPtr, Para1 p1, Para2 p2) :
                    _objPtr(objPtr), _funPtr(funPtr), _p1(p1), _p2(p2)
		{
		}
		virtual ~MemFunctor2()
		{
		}	
	public:
		virtual RtResult OnEventFire()
		{
			(_objPtr->*_funPtr)(_p1, _p2);
			return RT_OK;
		}
	private:
		ObjPtr _objPtr;
		FunPtr _funPtr;
		Para1  _p1;
		Para2  _p2;
	};

	template<typename ObjPtr, typename FunPtr, typename Para1, 
		     typename Para2, typename Para3>
	class MemFunctor3 : public Functor 
	{
	public:
		MemFunctor3(const ObjPtr& objPtr, const FunPtr& funPtr, Para1 p1, Para2 p2,
			        Para3 p3) : _objPtr(objPtr), _funPtr(funPtr), 
					_p1(p1), _p2(p2), _p3(p3)

		{
		}
		virtual ~MemFunctor3()
		{
			
		}	
	public:
		virtual RtResult OnEventFire()
		{
			 (_objPtr->*_funPtr)(_p1, _p2, _p3);
			 return RT_OK;
		}
	private:
		ObjPtr _objPtr;
		FunPtr _funPtr;
		Para1  _p1;
		Para2  _p2;
		Para3  _p3;
	};

	template<typename ObjPtr, typename FunPtr, typename Para1, 
		     typename Para2, typename Para3, typename Para4>
	class MemFunctor4 : public Functor 
	{
	public:
		MemFunctor4(const ObjPtr& objPtr, const FunPtr& funPtr, Para1 p1, Para2 p2,
			        Para3 p3, Para4 p4) : _objPtr(objPtr), _funPtr(funPtr), 
                    _p1(p1), _p2(p2), _p3(p3), _p4(p4)
			
		{
		}
		virtual ~MemFunctor4()
		{
		}	
	public:
		virtual RtResult OnEventFire()
		{
			(_objPtr->*_funPtr)(_p1, _p2, _p3, _p4);
			return RT_OK;
		}
	private:
		ObjPtr _objPtr;
		FunPtr _funPtr;
		Para1  _p1;
		Para2  _p2;
		Para3  _p3;
		Para4  _p4;
	};

	template<typename ObjPtr, typename FunPtr, typename Para1, 
		     typename Para2, typename Para3, typename Para4, typename Para5>
	class MemFunctor5 : public Functor 
	{
	public:
		MemFunctor5(const ObjPtr& objPtr, const FunPtr& funPtr, Para1 p1, Para2 p2,
			        Para3 p3, Para4 p4, Para5 p5) : _objPtr(objPtr), _funPtr(funPtr), 
			        _p1(p1), _p2(p2), _p3(p3), _p4(p4), _p5(p5)
			
		{
		}
		virtual ~MemFunctor5()
		{
		}	
	public:
		virtual RtResult OnEventFire()
		{
			(_objPtr->*_funPtr)(_p1, _p2, _p3, _p4, _p5);
			return RT_OK;
		}
	private:
		ObjPtr _objPtr;
		FunPtr _funPtr;
		Para1  _p1;
		Para2  _p2;
		Para3  _p3;
		Para4  _p4;
		Para5  _p5;
	};


	template<typename ObjPtr, typename FunPtr, typename Para1, 
		     typename Para2, typename Para3, typename Para4, typename Para5, 
		      typename Para6>
	class MemFunctor6 : public Functor 
	{
	public:
		MemFunctor6(const ObjPtr& objPtr, const FunPtr& funPtr, Para1 p1, Para2 p2,
			Para3 p3, Para4 p4, Para5 p5, Para6 p6) : _objPtr(objPtr), _funPtr(funPtr), 
			_p1(p1), _p2(p2), _p3(p3), _p4(p4), _p5(p5), _p6(p6)
			
		{
		}
		virtual ~MemFunctor6()
		{
		}	
	public:
		virtual RtResult OnEventFire()
		{
			(_objPtr->*_funPtr)(_p1, _p2, _p3, _p4, _p5, _p6);
			return RT_OK;
		}
	private:
		ObjPtr _objPtr;
		FunPtr _funPtr;
		Para1  _p1;
		Para2  _p2;
		Para3  _p3;
		Para4  _p4;
		Para5  _p5;
		Para6  _p6;
	};

}

#endif /*_NETFW_FUNCION_H*/
